package org.itboys.mobile.controller.site;

import org.apache.commons.lang.StringUtils;
import org.itboys.admin.entity.lasted.SystemDictionary;
import org.itboys.admin.service.lasted.SystemDictionaryService;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.ErrorException;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.dto.SundayAdvertisementDto;
import org.itboys.mobile.entity.mongo.*;
import org.itboys.mobile.entity.mysql.product.SundayProduct;
import org.itboys.mobile.entity.mysql.product.SundayProductCategory;
import org.itboys.mobile.entity.mysql.product.SundayProductRecord;
import org.itboys.mobile.service.mongo.site.*;
import org.itboys.mobile.service.mongo.web.SundayMemberService;
import org.itboys.mobile.service.mysql.site.SundaySiteProductRecordService;
import org.itboys.mobile.service.mysql.site.SundaySiteProductService;
import org.itboys.mobile.service.mysql.web.product.SundayProductCategoryService;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：zzq
 * 时间：2017/9/21
 * 描述：雄安加盟网_用户相关
 */
@Controller
@RequestMapping("/sunday/site/member")
public class SundaySiteMemberController extends BaseController{
    @Autowired
    private SundaySiteMemberService memberService;
    @Autowired
    private SundayProductCategoryService categoryService;
    @Autowired
    private SundaySiteProductService productService;
    @Autowired
    private JoinSiteShopService shopService;
    @Autowired
    private JoinSitePictureService pictureService;
    @Autowired
    private JoinSiteMessageService messageService;
    @Autowired
    private JoinSiteReplyMessageService replyMessageService;
    @Autowired
    private SystemDictionaryService dictionaryService;
    @Autowired
    private SundaySiteNewsService newsService;
    @Autowired
    private SundaySiteAdvertiseMentService advertiseMentService;
    @Autowired
    private SundaySiteMemberRecordService memberRecordService;
    @Autowired
    private SundaySiteProductRecordService productRecordService;
 /*   @RequestMapping("/batchSave")
    public void batchSave(HttpServletRequest request,
                         HttpServletResponse response
                        ){
        try{
            List<SundayProductCategory> categories=null;
            Map<String,Object> param=new HashMap<String,Object>();
            param.put("noParentId",2);
            categories=categoryService.select(param);
            for(SundayProductCategory category:categories){
                memberRecordService.batchSave(category.getId());
            }

            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
        }catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/sunday/site/member/save------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));
        }
    }*/
    /**
     * 公司注册主页
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/doRegister")
    public String  doRegister(HttpServletRequest request,
                         HttpServletResponse response, Model model){
        List<SundayProductCategory> categories= categoryService.getCategoryTreeJson();
        model.addAttribute("categories",categories);
        return "/join/site/member/doRegister";
    }

    /**
     * 普通用户注册
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/doRegisterMember")
    public String  doRegisterMember(HttpServletRequest request,
                              HttpServletResponse response, Model model){
        List<SundayProductCategory> categories= categoryService.getCategoryTreeJson();
        model.addAttribute("categories",categories);
        return "/join/site/member/doRegisterMember";
    }

    /**
     * 兼职页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/doRegisterJianzhi")
    public String  doRegisterJianzhi(HttpServletRequest request,
                                    HttpServletResponse response, Model model){
        List<SystemDictionary> roles=dictionaryService.getDictionaryByKey("jianzhi_role");
        model.addAttribute("roles",roles);
        return "/join/site/member/jianzhi";
    }
    /**
     * 兼职页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/doRegisterPartner")
    public String  doRegisterPartner(HttpServletRequest request,
                                     HttpServletResponse response, Model model){
        List<SystemDictionary> roles=dictionaryService.getDictionaryByKey("partner_role");
        model.addAttribute("roles",roles);
        return "/join/site/member/partner";
    }

    /**
     * 登录页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/doLogin")
    public String  doLogin(HttpServletRequest request,
                           HttpServletResponse response, Model model){

        return "/join/site/member/doLogin";
    }

    /**
     * 找回密码页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/doPassword")
    public String  findPassword(HttpServletRequest request,
                           HttpServletResponse response, Model model){

        return "/join/site/member/doPassword";
    }

    /**
     * 修改密码
     * @param request
     * @param response
     * @param phone
     * @param code
     * @param password
     */
    @RequestMapping("/changePassword")
    public void changPassword(HttpServletRequest request,
                      HttpServletResponse response,
                      @RequestParam(value="phone",required=true)String phone,
                      @RequestParam(value="code",required=true)String code,
                      @RequestParam(value="password",required=true)String password,
                              @RequestParam(value="yzm",required=true)String yzm
    ){
        try{
            //获取session的验证码
            String _yzm = (String) request.getSession().getAttribute("rand");
            if(!org.apache.commons.lang3.StringUtils.equals(_yzm, yzm)){
                throw new ErrorException("验证码错误");
            }
            memberRecordService.changePassword(phone,password,code);
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
        }catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/sunday/site/member/changPassword------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));
        }
    }

    /**
     * 登录
     * @param request
     * @param response
     * @param phone
     * @param password
     */
    @RequestMapping("/login")
    public void login(HttpServletRequest request,
                      HttpServletResponse response,
                      @RequestParam(value="phone",required=false)String phone,
                      @RequestParam(value="loginType",required=true)Integer loginType,
                      @RequestParam(value="userName",required=false)String userName,
                      @RequestParam(value="password",required=true)String password
    ){
        try{
            //获取session的验证码
            SundayMemberRecord memberRecord=memberRecordService.login(loginType,userName,phone,password);
            if(loginType==1){
                request.getSession().setAttribute("customer", memberRecord);
            }
            if(loginType==2){
                request.getSession().setAttribute("business", memberRecord);
            }

            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
        }catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/sunday/site/member/login------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));
        }
    }

    /**
     * 登出
     * @param request
     * @param response
     */
    @RequestMapping("/logout")
    public void logout(HttpServletRequest request,
                       HttpServletResponse response){
        try{
            HttpSession session=request.getSession();

            if(session.getAttribute("business")!=null){
                session.removeAttribute("business");
                AjaxUtils.renderJsonporJson(response, null,
                        ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
            }
            if(session.getAttribute("customer")!=null){
                session.removeAttribute("customer");
                AjaxUtils.renderJsonporJson(response, null,
                        ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
            }
        }catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErroException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/sunday/site/member/logout------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));
        }
    }
    /**
     * 前端注册
     * @param request
     * @param response
     * @param userType
     * @param userName
     * @param password
     * @param nickName
     * @param brandName
     * @param businessType
     * @param categoryId
     * @param categoryName
     * @param mobileName
     * @param mobile
     * @param phone
     * @param code
     */
    @RequestMapping("/register")
    public void register(HttpServletRequest request,
                         HttpServletResponse response,
                         @RequestParam(value="userType",required=true)Integer userType,
                         @RequestParam(value="userName",required=true)String userName,
                         @RequestParam(value="password",required=true)String password,
                         @RequestParam(value="nickName",required=false)String nickName,
                         @RequestParam(value="brandName",required=false)String brandName,
                         @RequestParam(value="businessType",required=false)String businessType,
                         @RequestParam(value="categoryId",required=false)Long categoryId,
                         @RequestParam(value="categoryName",required=false)String categoryName,
                         @RequestParam(value="mobileName",required=false)String mobileName,
                         @RequestParam(value="mobile",required=false)String mobile,
                         @RequestParam(value="phone",required=false)String phone,
                         @RequestParam(value="code",required=false)String code,
                         @RequestParam(value="yzm",required=false)String yzm){
        try{
            //获取session的验证码
         /*   String _yzm = (String) request.getSession().getAttribute("rand");
            if(!org.apache.commons.lang3.StringUtils.equals(_yzm, yzm)){
                throw new ErrorException("验证码错误");
            }*/
            memberRecordService.save(userType,userName,password,nickName,brandName,businessType,
                    categoryId,categoryName,mobileName,mobile,phone,code);
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
        }catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/sunday/site/member/save------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));
        }
    }

    /**
     * 注册普通用户
     * @param request
     * @param response
     * @param phone
     * @param password
     * @param sex
     * @param code
     * @param yzm
     */
    @RequestMapping("/registerMember")
    public void register(HttpServletRequest request,
                         HttpServletResponse response,
                         @RequestParam(value="phone",required=false)String phone,
                         @RequestParam(value="password",required=true)String password,
                         @RequestParam(value="sex",required=true)String  sex,
                         @RequestParam(value="code",required=false)String code,
                         @RequestParam(value="yzm",required=true)String yzm){
        try{
            //获取session的验证码
            String _yzm = (String) request.getSession().getAttribute("rand");
            if(!org.apache.commons.lang3.StringUtils.equals(_yzm, yzm)){
                throw new ErrorException("验证码错误");
            }
            memberRecordService.save(phone,password,code,sex);
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
        }catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/sunday/site/member/saveMember------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));
        }
    }



/**---------------------------------------------个人用户部分开始--------------------------------------------------------------*/
    /**
     * 个人主页
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/member/index")
    public String  memberIndex(HttpServletRequest request,
                                HttpServletResponse response, Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("customer");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        //获取关注数量
        PageResult<SundayProduct> favoriteResult=productService.selectMemberFavoriteProduct(request,memberRecord.getId(),null);
        model.addAttribute("favoriteNum",favoriteResult.getTotal());
        //获取首页需要的项目
        Map<String ,Object> result=productService.selectMemberIndexProduct(memberRecord.getId());
        model.addAttribute("result",result);
        //加载轮播图
        List<SundayAdvertisementDto> customer_rolls =advertiseMentService.getAdvertisementByZone("customer_roll");
        model.addAttribute("customer_rolls",customer_rolls);

        return "/join/site/member/member/index";
    }

    /**
     * 个人用户资料页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/member/data")
    public String  memberData(HttpServletRequest request,
                               HttpServletResponse response, Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("customer");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        //获取关注数量
        PageResult<SundayProduct> favoriteResult=productService.selectMemberFavoriteProduct(request,memberRecord.getId(),null);
        model.addAttribute("favoriteNum",favoriteResult.getTotal());
        List<SystemDictionary> amounts=dictionaryService.getDictionaryByKey("invest_amount");
        model.addAttribute("amounts",amounts);
        return "/join/site/member/member/data";
    }

    /**
     * 个人用户留言页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/member/message")
    public String  memberMessage(HttpServletRequest request,
                              HttpServletResponse response,
                                 @RequestParam(value="page",required=false)Integer page,
                                 @RequestParam(value="status",required=false)Integer status,
                                 Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("customer");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        //获取关注数量
        PageResult<SundayProduct> favoriteResult=productService.selectMemberFavoriteProduct(request,memberRecord.getId(),null);
        model.addAttribute("favoriteNum",favoriteResult.getTotal());

        PageResult<JoinMessage> result=messageService.selectMemberMessage(request,memberRecord.getId(),status);
        Long totalPage=result.getTotal()/ SundayCommonConstants.row_size+1;
        model.addAttribute("totalPage",totalPage);
        model.addAttribute("currentPage",page);
        model.addAttribute("messages",result.getData());
        model.addAttribute("status",status);
        List<JoinReplyMessage> replyMessages=replyMessageService.selectMemberMessage(memberRecord.getId());
        model.addAttribute("replyMessages",replyMessages);
        return "/join/site/member/member/message";
    }

    /**
     * 个人用户关注项目页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/member/favorite")
    public String  memberFavorite(HttpServletRequest request,
                               HttpServletResponse response,
                                  @RequestParam(value="page",required=false)Integer page,
                                  Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("customer");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        //获取关注数量
        PageResult<SundayProduct> favoriteResult=productService.selectMemberFavoriteProduct(request,memberRecord.getId(),null);

        //分页获取关注的项目
        PageResult<SundayProduct> result=productService.selectMemberFavoriteProduct(request,memberRecord.getId(),page);
        if(ListUtil.isNull(result.getData())){
            model.addAttribute("favoriteNum",0);
            model.addAttribute("totalPage",1);
        }else {
            model.addAttribute("favoriteNum",result.getTotal());
            Long totalPage=result.getTotal()/ SundayCommonConstants.row_size+1;
            model.addAttribute("totalPage",totalPage);
        }
        model.addAttribute("currentPage",page);
        model.addAttribute("products",result.getData());

        return "/join/site/member/member/favorite";
    }
    /**
     * 修改个人用户信息
     * @param request
     * @param response
     * @param memberId
     * @param nickName
     * @param sex
     * @param marriage
     * @param birthDay
     * @param idCard
     * @param desc
     */
    @RequestMapping("/updateDataMember")
    public void updateDataMember(HttpServletRequest request,
                                 HttpServletResponse response,
                                 @RequestParam(value="memberId",required=true)Long memberId,
                                 @RequestParam(value="nickName",required=false)String  nickName,
                                 @RequestParam(value="sex",required=false)String sex,
                                 @RequestParam(value="marriage",required=false)String marriage,
                                 @RequestParam(value="phone",required=false)String phone,
                                 @RequestParam(value="birthDay",required=false)String birthDay,
                                 @RequestParam(value="idCard",required=false)String idCard,
                                 @RequestParam(value="desc",required=false)String desc,
                                 @RequestParam(value="selfAmount",required=false)String selfAmount
    ){
        try{
            memberRecordService.updateDataMember(memberId,nickName,sex,marriage,phone,birthDay,idCard,desc,selfAmount);
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
        }catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/sunday/site/member/updateDataMember------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));
        }
    }

    /**---------------------------------------------个人用户部分结束--------------------------------------------------------------*/



    /**---------------------------------------------企业部分开始--------------------------------------------------------------*/
    /**
     * 公司主页
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/company/index")
    public String  companyIndex(HttpServletRequest request,
                                HttpServletResponse response, Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("business");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }

        SundayProductRecord productRecord=productRecordService.findOneByMember(memberRecord.getId());

        SundayProduct product=productService.find(productService.getIdByRecord(productRecord.getId()));
        model.addAttribute("realProduct",product);
        Long productId=0l;
        if(product!=null){
            productId=product.getId();
        }
        //获取留言统计
        Map<String,Object> messageNums=messageService.getIndexMessageNum(productId);
        model.addAttribute("messageNums",messageNums);
        //获取推荐的资讯
        List<SundayNews> newss=newsService.getRecommendNews();
        model.addAttribute("newss",newss);
        return "/join/site/member/company/index";
    }
    /**
     *
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/company/data")
    public String  companyData(HttpServletRequest request,
                                HttpServletResponse response, Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("business");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        SundayProductRecord productRecord=productRecordService.findOneByMember(memberRecord.getId());
        productRecordService.packageTags(productRecord,true);
        model.addAttribute("product",productRecord);

        SundayProduct product=productService.find(productService.getIdByRecord(productRecord.getId()));
        model.addAttribute("realProduct",product);
        return "/join/site/member/company/data";
    }

    /**
     * 我的客户页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/company/customer")
    public String  companyCustomer(HttpServletRequest request,
                               HttpServletResponse response,
                                   @RequestParam(value="page",required=false)Integer page,
                                   @RequestParam(value="provinceId",required=false)Long provinceId,
                                   @RequestParam(value="cityId",required=false)Long cityId,
                                   @RequestParam(value="districtId",required=false)Long districtId,
                                   @RequestParam(value="mobile",required=false)String mobile,
                                   @RequestParam(value="status",required=false)Integer status,
                                   @RequestParam(value="name",required=false)String  name,
                                   @RequestParam(value="content",required=false)String content,
                                   Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("business");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        SundayProductRecord productRecord=productRecordService.findOneByMember(memberRecord.getId());
        SundayProduct product=productService.find(productService.getIdByRecord(productRecord.getId()));
        model.addAttribute("realProduct",product);
        PageResult<JoinMessage> result=messageService.selectProductMessage(request,productService.getIdByRecord(productRecord.getId()),provinceId,cityId,districtId,mobile,
                status,name,content);
        model.addAttribute("messages",result.getData());
        List<JoinReplyMessage> replyMessages=replyMessageService.selectProductMessage(productService.getIdByRecord(productRecord.getId()));
        model.addAttribute("replyMessages",replyMessages);
        model.addAttribute("currentPage",page);
        model.addAttribute("totalPage",result.getTotal()/10+1);
        model.addAttribute("provinceId",provinceId);
        model.addAttribute("cityId",cityId);
        model.addAttribute("districtId",districtId);
        model.addAttribute("mobile",mobile);
        model.addAttribute("status",status);
        model.addAttribute("name",name);
        model.addAttribute("content",content);

        return "/join/site/member/company/message";
    }

    /**
     * 企业资质认证页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/company/aptitude")
    public String  companyAptitude(HttpServletRequest request,
                                   HttpServletResponse response, Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("business");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        SundayProductRecord productRecord=productRecordService.findOneByMember(memberRecord.getId());
        model.addAttribute("product",productRecord);
        //获取真实项目
        SundayProduct product=productService.find(productService.getIdByRecord(productRecord.getId()));
        model.addAttribute("realProduct",product);
        return "/join/site/member/company/aptitude";
    }

    /**
     * 企业加盟费用页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/company/cost")
    public String  companyCost(HttpServletRequest request,
                                   HttpServletResponse response, Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("business");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        SundayProductRecord productRecord=productRecordService.findOneByMember(memberRecord.getId());
        model.addAttribute("product",productRecord);
        //获取真实项目
        SundayProduct product=productService.find(productService.getIdByRecord(productRecord.getId()));
        model.addAttribute("realProduct",product);
        return "/join/site/member/company/cost";
    }

    /**
     * 企业加盟详情页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/company/detail")
    public String  detail(HttpServletRequest request,
                               HttpServletResponse response, Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("business");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        SundayProductRecord productRecord=productRecordService.findOneByMember(memberRecord.getId());
        model.addAttribute("product",productRecord);
        //获取真实项目
        SundayProduct product=productService.find(productService.getIdByRecord(productRecord.getId()));
        model.addAttribute("realProduct",product);
        return "/join/site/member/company/detail";
    }

    /**
     * 企业加盟优势页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/company/advantage")
    public String  companyAdvantage(HttpServletRequest request,
                               HttpServletResponse response, Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("business");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        SundayProductRecord productRecord=productRecordService.findOneByMember(memberRecord.getId());
        model.addAttribute("product",productRecord);
        //获取真实项目
        SundayProduct product=productService.find(productService.getIdByRecord(productRecord.getId()));
        model.addAttribute("realProduct",product);
        return "/join/site/member/company/advantage";
    }

    /**
     * 企业加盟店铺页面
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/company/shop")
    public String  companyShop(HttpServletRequest request,
                                    HttpServletResponse response,
                               @RequestParam(value="page",required=false)Integer page,
                               Model model){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("business");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        SundayProductRecord productRecord=productRecordService.findOneByMember(memberRecord.getId());
        productRecordService.packageTags(productRecord,true);
        model.addAttribute("product",productRecord);
        //获取真实项目
        SundayProduct product=productService.find(productService.getIdByRecord(productRecord.getId()));
        model.addAttribute("realProduct",product);
        PageResult<JoinShop> result=shopService.selectByProductId(request,productRecord.getId());
        model.addAttribute("currentPage",page);
        model.addAttribute("totalPage",result.getTotal()/10+1);
        model.addAttribute("shops",result.getData());
        return "/join/site/member/company/shop";
    }

    /**
     * 企业图库
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/company/picture")
    public String  companyPicture(HttpServletRequest request,
                               HttpServletResponse response, Model model,
                                  @RequestParam(value="type",required=false)Integer type){
        HttpSession session=request.getSession();
        SundayMemberRecord memberRecord=(SundayMemberRecord) session.getAttribute("business");
        if(memberRecord==null){
            return "/join/site/member/doLogin";
        }
        SundayProductRecord productRecord=productRecordService.findOneByMember(memberRecord.getId());
        model.addAttribute("product",productRecord);
        //获取真实项目
        SundayProduct product=productService.find(productService.getIdByRecord(productRecord.getId()));
        model.addAttribute("realProduct",product);
        List<JoinPicture> pictures=pictureService.select(request,memberRecord.getId(),type);
        model.addAttribute("pictures",pictures);
        if(type!=null){
            model.addAttribute("type",type);
        }
        return "/join/site/member/company/picture";
    }




    @RequestMapping("/company/update")
    public void companyUpdate(HttpServletRequest request,
                     HttpServletResponse response,

                              @RequestParam(value="businessId",required=true)Long businessId,
                              @RequestParam(value="productId",required=true)Long productId,
                              @RequestParam(value="nickName",required=false)String nickName,
                              @RequestParam(value="mobileName",required=false)String mobileName,
                              @RequestParam(value="phone",required=false)String phone,
                              @RequestParam(value="mobile",required=false)String mobile,
                              @RequestParam(value="email",required=false) String email,
                              @RequestParam(value="qqNumber",required=false) String qqNumber,
                              @RequestParam(value="faxNumber",required=false) String faxNumber,
                              @RequestParam(value="englishName",required=false) String englishName,
                              @RequestParam(value="businessSite",required=false) String businessSite,
                              @RequestParam(value="businessType",required=false) String businessType,
                              @RequestParam(value="generateTime",required=false) String generateTime,
                              @RequestParam(value="corporation",required=false) String corporation,
                              @RequestParam(value="amount",required=false) String amount,
                              @RequestParam(value="provinceId",required=false) Long provinceId,
                              @RequestParam(value="provinceName",required=false) String provinceName,
                              @RequestParam(value="cityId",required=false) Long cityId,
                              @RequestParam(value="cityName",required=false) String cityName,
                              @RequestParam(value="districtId",required=false) Long districtId,
                              @RequestParam(value="districtName",required=false) String districtName,
                              @RequestParam(value="address",required=false) String address,
                              @RequestParam(value="creditNum",required=false) String creditNum,
                              @RequestParam(value="licenseNum",required=false) String licenseNum,
                              @RequestParam(value="taxNum",required=false) String taxNum,
                              @RequestParam(value="institutionalNum",required=false) String institutionalNum,
                              @RequestParam(value="brandName",required=false) String brandName,
                              @RequestParam(value="brandEnglishName",required=false) String brandEnglishName,
                              @RequestParam(value="brandLogo",required=false) String brandLogo,
                              @RequestParam(value="brandSource",required=false) String brandSource,
                              @RequestParam(value="brandGenerateTime",required=false) String brandGenerateTime,
                              @RequestParam(value="brandRegisterNum",required=false) String brandRegisterNum,

                              //项目部分
                              @RequestParam(value="productName",required=false)  String productName,
                              @RequestParam(value="productViceName",required=false)  String productViceName,
                              @RequestParam(value="keyWord",required=false)  String keyWord,
                              @RequestParam(value="desc",required=false)  String desc,
                              @RequestParam(value="investAmount",required=false)  String investAmount,
                              @RequestParam(value="joinModel",required=false)  String joinModel,
                              @RequestParam(value="joinArea",required=false)  String joinArea,
                              @RequestParam(value="isAreaAuthorization",required=false)  Integer isAreaAuthorization,
                              @RequestParam(value="limitTime",required=false)  String  limitTime,
                              @RequestParam(value="directShopNum",required=false)  Integer directShopNum,
                              @RequestParam(value="joinShopNum",required=false)  Integer joinShopNum,
                              @RequestParam(value="isBusinessBack",required=false)  Integer isBusinessBack,
                              @RequestParam(value="products",required=false)  String products,
                              @RequestParam(value="managerModel",required=false)  String managerModel,
                              @RequestParam(value="fitPerson",required=false)  String fitPerson,
                              @RequestParam(value="image",required=false)  String image

                              ){
        try{

                memberRecordService.updateDataBusiness(businessId, productId,
                        //企业部分
                        nickName, mobileName,phone,mobile,email,qqNumber,faxNumber,englishName,businessSite, businessType,generateTime,corporation,amount,
                        provinceId,provinceName,cityId,cityName,districtId,districtName,address,
                        creditNum,licenseNum,taxNum,institutionalNum,
                        brandName,brandEnglishName,brandLogo,brandSource,brandGenerateTime,brandRegisterNum,
                        //项目部分
                        productName,productViceName,keyWord,desc,
                        investAmount,joinModel,joinArea,isAreaAuthorization,limitTime,directShopNum,joinShopNum,isBusinessBack,products,
                        managerModel,fitPerson,image);
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
        }catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErroException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/sunday/site/member/company/update------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));
        }
    }



    /**
     * 企业资质审核相关内容
     * @param request
     * @param response
     * @param businessId
     * @param licenseImg
     * @param institutionalImg
     * @param taxImg
     * @param brandRegisterImg
     * @param businessBackImg
     * @param patentImg
     */
    @RequestMapping("/updateDataBusiness")
    public void updateDataBusiness(HttpServletRequest request,
                      HttpServletResponse response,
                      @RequestParam(value="businessId",required=true)Long businessId,
                      @RequestParam(value="licenseImg",required=false)String  licenseImg,
                      @RequestParam(value="institutionalImg",required=false)String institutionalImg,
                      @RequestParam(value="taxImg",required=false)String taxImg,
                      @RequestParam(value="brandRegisterImg",required=false)String brandRegisterImg,
                      @RequestParam(value="businessBackImg",required=false)String businessBackImg,
                      @RequestParam(value="patentImg",required=false)String patentImg
    ){
        try{
            memberRecordService.updateDataBusiness(businessId,licenseImg,institutionalImg,taxImg,brandRegisterImg,businessBackImg,patentImg);
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
        }catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/sunday/site/member/updateDataBusiness------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));
        }
    }
    /**
     * 修改资料
     * @param request
     * @param response
     * @param productId
     * @param joinFee
     * @param joinAdvantage
     * @param joinProcess
     */
    @RequestMapping("company/updateDesc")
    public void updateData(HttpServletRequest request,
                           HttpServletResponse response,
                           @RequestParam(value="productId",required=true)Long productId,
                           @RequestParam(value="joinFee",required=false)String  joinFee,
                           @RequestParam(value="joinAdvantage",required=false)String joinAdvantage,
                           @RequestParam(value="joinProcess",required=false)String joinProcess,
                           @RequestParam(value="detail",required=false)String detail
    ){
        try{
            productRecordService.updateData(productId,joinFee,joinAdvantage,joinProcess,detail);
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
        }catch (Exception e) {
            String msg = "";
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
            } else {
                msg = CommonConstants.ERROMSG;
                logger.error("/sunday/site/member/updateData------" + e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,msg));
        }
    }
    /**----------------------------------企业部分结束-----------------------------------------------------------------------------*/

}
